package com.just.school_campus.service.impl;

import com.just.school_campus.dao.ShopCarMapper;
import com.just.school_campus.model.ShopCar;
import com.just.school_campus.model.ShopCarExample;
import com.just.school_campus.service.ShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopCarServiceImpl implements ShopCarService {
    @Autowired
    private ShopCarMapper shopCarDao;

    @Override
    public List<ShopCar> findAllByUid(String userId) {
        ShopCarExample example = new ShopCarExample();
        example.createCriteria().andUserIdEqualTo(userId);
        return shopCarDao.selectByExample(example);
    }

    @Override
    public int deleteOneByUidAndGid(ShopCar shopCar) {
        ShopCarExample example = new ShopCarExample();
        example.createCriteria().andUserIdEqualTo(shopCar.getUserId())
                .andGoodsIdEqualTo(shopCar.getGoodsId());
        return shopCarDao.deleteByExample(example);
    }

    @Override
    public int deleteAllByUid(String userId) {
        ShopCarExample example = new ShopCarExample();
        example.createCriteria().andUserIdEqualTo(userId);
        return shopCarDao.deleteByExample(example);
    }

    @Override
    public int addOneToShopCar(ShopCar shopCar) {
        return shopCarDao.insertSelective(shopCar);
    }
}
